Solved

Issue with loading image in Mac/Safai

Posted on 2007-11-27
11
546 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
Instantly Create Instructional Tutorials

Contextual Guidance at the moment of need helps your employees adopt to new software or processes instantly. Boost knowledge retention and employee engagement step-by-step with one easy solution.

 
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

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

Question has a verified solution.

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

We could spend the next millennium discussing the differences of the Mac and Windows platforms. The next century will continue to have fanatics on both side of the equation and neither side will win the war. However, that’s not why we are here. W…
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn the basics of jQuery including how to code hide show and toggles. 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…
This Micro Tutorial will demonstrate how to add subdomains to your content reports. This can be very importing in having a site with multiple subdomains.

688 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