Solved

Issue with loading image in Mac/Safai

Posted on 2007-11-27
11
545 Views
Last Modified: 2013-12-07
I am unable to load image in Safari browser with Mac OS. The same is loaded perfectly fine in IE, Firefox browsers in Windows and Mac OS.
The javascript line which is failing is

this.oImage = new Image;

Thanks



0
Comment
Question by:RNK
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2
  • 2
  • +2
11 Comments
 
LVL 7

Expert Comment

by:Maverick_Cool
ID: 20359780
First check what object does this refer in these browsers
0
 

Author Comment

by:RNK
ID: 20359868
The Image object should be HTMLImageElement
0
 
LVL 21

Expert Comment

by:nizsmo
ID: 20360286
Are you able to give an example?
0
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
LVL 21

Expert Comment

by:nizsmo
ID: 20360293
0
 

Author Comment

by:RNK
ID: 20369354
var newImg = new Image();
newImg.src = src;
Img.width = newImg.width;
Img.height = newImg.height;

Img.src = src;

does not seem to be assigning the height and width correctly
0
 
LVL 21

Accepted Solution

by:
nizsmo earned 84 total points
ID: 20369708
Where does your Img variable come from? is it an ID from the image tag? eg if you have something like this:
<img id="test_image" src="..." ....>

you can do something like this in javascript:
var newImg = new Image();
test_img = document.getElementById('test_image');
newImg.src = src;
test_img.width = newImg.width;
test_img.height = newImg.height;

test_img.src = src;


hope this helps.
0
 
LVL 7

Assisted Solution

by:Maverick_Cool
Maverick_Cool earned 83 total points
ID: 20371771
use <object>.style.width instead <object>.width.

style has more effect/precedence
0
 
LVL 75

Assisted Solution

by:Michel Plungjan
Michel Plungjan earned 83 total points
ID: 20374286
Some browsers executes the next statement after src= immediately so the height and width is not available
Some older browsers cannot change the size of a rendered image

try this:


var Img = null; // global var
function resizeIt() {
  Img.width = this.width;
  Img.height = this.height;
  Img.src = this.src;
}

function loadImage(theImg,src) {
  Img = theImg;
  var newImg = new Image();
  newImg.onload=resizeIt;
  newImg.src = src;
}


0
 
LVL 75

Expert Comment

by:Michel Plungjan
ID: 20374299
and call it like

<a href="#"
onClick="loadImage(document.getElementById('img1'),'test.jpg'); return false">Load</a>
<img src="dummy.jpg" id="img1">
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21447817
Forced accept.

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

In this article we will discuss some EI Capitan Mail app issues and provide some manual process to resolve them.
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

726 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question