Solved

Issue with loading image in Mac/Safai

Posted on 2007-11-27
11
542 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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

Do You Know the 4 Main Threat Actor Types?

Do you know the main threat actor types? Most attackers fall into one of four categories, each with their own favored tactics, techniques, and procedures.

Join & Write a Comment

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…
SSL stands for “Secure Sockets Layer” and an SSL certificate is a critical component to keeping your website safe, secured, and compliant. Any ecommerce website must have an SSL certificate to ensure the safe handling of sensitive information like…
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)
How to create a custom search shortcut to site-search Experts Exchange using Google in the Firefox browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch your Bookmark Menu: Press 'Ctrl +…

706 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

15 Experts available now in Live!

Get 1:1 Help Now