473,803 Members | 3,943 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Safari: img within a link object?

I'm attempting to dynamically add a link so I can take a mouseover
action on it and am having problems in Safari (this works fine in
Firefox and IE (Windows version of IE)). When I add the img object it
shows fine, but when I try to contain it within a link, it does not
display. I've tried using the IE and non-IE method below but neither
seem to work. Is this a bug in Safari or is there a different way to
achieve this? I was testing with Safari 1.3.2 on OS X 10.3.x

if (!isIE) {
oldImage = document.create Element("img");
oldImage.src = value;
oldImage.title = "";
newImage = document.create Element("link") ;
newImage.append Child(oldImage) ;
} else {
newImage = document.create Element("<img src='" + value + " '
title='" + "" + "'>");
}
newImage.onmous eover = function(){
takeAction();
};
newImage.onmous eout = function(){
takeAction();
}

Thanks,
Steve

Apr 19 '06 #1
4 2313
zo******@gmail. com wrote :
I'm attempting to dynamically add a link so I can take a mouseover
action on it and am having problems in Safari (this works fine in
Firefox and IE (Windows version of IE)). When I add the img object it
shows fine, but when I try to contain it within a link, it does not
display. I've tried using the IE and non-IE method below but neither
seem to work. Is this a bug in Safari or is there a different way to
achieve this? I was testing with Safari 1.3.2 on OS X 10.3.x

if (!isIE) {
Modern ways to detect browsers involve only object/features detection:
this method is more reliable and easier to implement and easier to manage.

Developing Cross Browser/Cross Platform Pages
http://www.mozilla.org/docs/web-deve...evCrossBrowser

Browser identification approach (aka "browser sniffing"): not best, not
reliable approach
http://www.mozilla.org/docs/web-deve...l#BrowserIdent

Using Object/Feature detection approach: best and overall most reliable
http://www.mozilla.org/docs/web-deve...jectFeatDetect

A Strategy That Works: Object/Feature Detecting by comp.lang.javas cript
newsgroup FAQ notes
http://jibbering.com/faq/faq_notes/n...tect.html#bdFD

Browser detection - No; Object detection - Yes by Peter-Paul Koch
http://www.quirksmode.org/js/support.html

oldImage = document.create Element("img");
oldImage.src = value;
oldImage.title = "";
newImage = document.create Element("link") ;
This way of defining variables is weird and not recommendable (from a
debugging perspective, reviewing by others, reusing code, etc.): the
variable identifier says it's a new image but the execution only
involves the creation of a link. So, it's misleading.
newImage.append Child(oldImage) ;
Shouldn't it be an anchor then? An <a>, not a <link>.

} else {
newImage = document.create Element("<img src='" + value + " '
title='" + "" + "'>");
}
newImage.onmous eover = function(){
takeAction();
};
newImage.onmous eout = function(){
takeAction();
}

Thanks,
Steve


Ok. I think I understand what you're trying to do here.

Try this:

if (document.creat eElement)
{
var oldImage = document.create Element("img");
oldImage.width = 100; // change that value
oldImage.height = 50; // change that value
oldImage.src = value;
oldImage.alt = "[some descriptive text]";

var objLink = document.create Element("a");
objLink.href = "[path]/filename.ext"; // change accordingly that
value
objLink.onmouse over = new Function ("evt", "takeAction()") ;
objLink.onmouse out = new Function ("evt", "takeAction()") ;
objLink.appendC hild(oldImage);
}

Gérard
--
remove blah to email me
Apr 19 '06 #2
zo******@gmail. com wrote:
I'm attempting to dynamically add a link so I can take a mouseover
action on it and am having problems in Safari (this works fine in
Firefox and IE (Windows version of IE)). When I add the img object it
shows fine, but when I try to contain it within a link, it does not
display. I've tried using the IE and non-IE method below but neither
seem to work. Is this a bug in Safari or is there a different way to
achieve this? I was testing with Safari 1.3.2 on OS X 10.3.x

if (!isIE) {
oldImage = document.create Element("img");
oldImage.src = value;
oldImage.title = "";
newImage = document.create Element("link") ;
newImage.append Child(oldImage) ;
} else {
newImage = document.create Element("<img src='" + value + " '
title='" + "" + "'>");
}
newImage.onmous eover = function(){
takeAction();
};
newImage.onmous eout = function(){
takeAction();
}


Are you sure you meant to create a '<link>' element rather than an <a>?

Are you appending the link element to anything?

Does this test do the sort of thing you wanted?

<html>
<body>
<script type="text/javascript"/">

function makePicLink(par entElem, onFunc, outFunc, addr, pic)
{
var aLink, clickImg;

aLink=document. createElement(' a');
aLink.href=addr ;
aLink.onmouseov er=onFunc;
aLink.onmouseou t=outFunc;
parentElem.appe ndChild( aLink );

clickImg=docume nt.createElemen t('img');
clickImg.src=pi c;
aLink.appendChi ld( clickImg );

}

makePicLink(doc ument.body, function(){docu ment.bgColor='# ff8000'},
function(){docu ment.bgColor='# ffffff'}, '#', 'smiley.gif' );

</script>
</body>
</html>

Apr 19 '06 #3
ASM
zo******@gmail. com a écrit :
Is this a bug in Safari or is there a different way to
achieve this? I was testing with Safari 1.3.2 on OS X 10.3.x

if (!isIE) {
oldImage = document.create Element("img");
oldImage.src = value;
oldImage.title = "";
newImage = document.create Element("link") ;


newImage = document.create Element("A");

did you ever see a tag 'link' in body ?

--
Stephane Moriaux et son [moins] vieux Mac
Apr 24 '06 #4
ASM
Gérard Talbot a écrit :
zo******@gmail. com wrote :
if (!isIE) {
Modern ways to detect browsers involve only object/features detection:
this method is more reliable and easier to implement and easier to manage.


if you want to keep IE away you want to keep IE away !

isIE = false; /*@cc_on isIE=true; @*/

any need of complications
Try this:
OK that works in my IE (5.2 Mac)

But I have a problem with this IE
if I do :

var inpoot = document.create Element("input" );
inpoot.type = 'text';

my IE stops here : "type is read only" does it clam.

How would you detect this soup ?

if (document.creat eElement)
{
var oldImage = document.create Element("img");
oldImage.width = 100; // change that value
oldImage.height = 50; // change that value
oldImage.src = value;
oldImage.alt = "[some descriptive text]";

var objLink = document.create Element("a");
objLink.href = "[path]/filename.ext"; // change accordingly that
value
objLink.onmouse over = new Function ("evt", "takeAction()") ;
objLink.onmouse out = new Function ("evt", "takeAction()") ;
objLink.appendC hild(oldImage);
}

--
Stephane Moriaux et son [moins] vieux Mac
Apr 24 '06 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
8822
by: Mark Anderson | last post by:
Sorry if this is a rookie mistake... I've been through all the FAQs and the books I have but I can't see the mistake so I guess it's something simple <g> - I'm an occasional JS user. I've got some code (in an external JS file) attached to a number of links off a query result page. The code it checks if there are any ticked items on the page and adds them to a lightbox (cart) before going the next called result page. The idea is to stop...
4
2732
by: Paul W | last post by:
Hi - can someone point me to info on the issues/resolutions of supporting the safari browser? To help me understand, if I was developing pages in say FrontPage, what attributes would I set for 'target browser'? I'm having a helluva time with table layouts etc and goin' stir crazy.. Thanks, Paul.
2
1557
by: vendredi5h | last post by:
Hello, Yesterday I spent a lot of time to find why my javascript script was not working on Safari. I finaly found a solution but not the reason. And I'd like to know if someone could tell me if what seems to be an esotheric bug is actualy not! Here is the problematic part: -------------------------------
7
2128
by: ja | last post by:
Hi, I've made an pseudo-select, wich using DOM functions like: document.createElement() appendChild() document.getElementById() with(obj){
11
2461
by: Stevo | last post by:
I've been using the unload event for a long time. I have this code, which I've abstracted and made into a stripped down simple test case below, and it works fine on the major browsers (IE5+, Firefox, Opera). It also works for all Safari versions before 3.1. It's as if they've deliberately made a change to prevent some actions in the unload handler. Has anyone heard of such a restriction? Here's the test case:
7
5226
by: David Stone | last post by:
Run into something recently that has left me a little puzzled. According to the examples in section 13.6.1 of html 4.01... <http://www.w3.org/TR/html401/struct/objects.html#h-13.6.1.1> I should be able to use <aelements with a specified shape and coords within a <mapso that I can use the links with an actual image and, at the same time, have the links appear as text. Something like the map associated with
3
4047
by: Brad | last post by:
I have an aspx page that is sending pdf files to client browsers: it uses a filestream to read the pdf file and response.binarywrite to send content to the browser. This has worked great for years in IE, Firefox and Opera on windows, and it works on a Mac with Firefox and Opera. But this fails in Safari with the generic message "A network error occurred while accessing this document". Here is a link to try out ...
15
2675
by: GinnTech | last post by:
I have a site that works perfectly in IE6 IE7 FF2 FF3 but not in the latest Safari. Here is the issue. I am attempting to call functions within a flash object. When trying to attempt to retrieve the object to call the functions IE6 IE7 FF2 FF3 all return Objects to work with. In Safari a function is returned. Here is the code. /
0
10548
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10316
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10295
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
7604
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6842
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5500
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5629
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3798
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2970
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.