Solved

Issue with loading image in Mac/Safai

Posted on 2007-11-27
11
543 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
  • 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
 
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
Comprehensive Backup Solutions for Microsoft

Acronis protects the complete Microsoft technology stack: Windows Server, Windows PC, laptop and Surface data; Microsoft business applications; Microsoft Hyper-V; Azure VMs; Microsoft Windows Server 2016; Microsoft Exchange 2016 and SQL Server 2016.

 
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

Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

Question has a verified solution.

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

Suggested Solutions

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…
I annotated my article on ransomware somewhat extensively, but I keep adding new references and wanted to put a link to the reference library.  Despite all the reference tools I have on hand, it was not easy to find a way to do this easily. I finall…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
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.

911 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

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now