469,625 Members | 1,807 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,625 developers. It's quick & easy.

problem with safari

ja
Hi,

I've made an pseudo-select, wich using DOM functions like:

document.createElement()
appendChild()

document.getElementById()

with(obj){
style.something = 'somethingElse';
}

obj.onmouseover= new Function();

here you can see source code:
http://viamigo.com/javaScript/pulldownMenu.js
here it's working (ie select country):
http://viamigo.com/

the problem is, that it's working on:
ie, opera, netscape, firefox(win, linux), konqueror, swift
(http://en.wikipedia.org/wiki/Swift_%28web_browser%29)
but not in safari, i have no mac so i'm not able to find error...

somebody can help me with this, please?

Cheers
wojtek
Nov 13 '06 #1
7 1899
i dont have OSX or i would help, but it looks a very nice piece of
work, you reveal path info during the upload progress XHR but what I
have seen looks good.

Nov 13 '06 #2
ja wrote:
Hi,

I've made an pseudo-select, wich using DOM functions like:

document.createElement()
appendChild()

document.getElementById()

with(obj){
style.something = 'somethingElse';
}

obj.onmouseover= new Function();

here you can see source code:
http://viamigo.com/javaScript/pulldownMenu.js
here it's working (ie select country):
http://viamigo.com/

the problem is, that it's working on:
ie, opera, netscape, firefox(win, linux), konqueror, swift
(http://en.wikipedia.org/wiki/Swift_%28web_browser%29)
but not in safari, i have no mac so i'm not able to find error...

somebody can help me with this, please?
Unlikely, there are over 500 lines of code and Safari doesn't produce
any error messages. Start with the errors reported by Firefox:

Error: not well-formed
Source File: http://viamigo.com/php/geoip.php
Line: 1, Column: 5
Source Code:
a:9:{i:0;a:3:...

Error: not well-formed
Source File: http://viamigo.com/php/pullDowns.php
Line: 1, Column: 5
Source Code:
a:4:{i:0;a:2:...

Error: not well-formed
Source File: http://viamigo.com/php/pullDowns.php
Line: 1, Column: 5
Source Code:
a:3:{i:0;a:2:...

I've trimmed them, hopefully you can see where the errors are. There
are also some CSS errors, but they are likely irrelevant to the issue.

I'm also rather bemused by functions like:

function entenityToString (htmlMarkup) {
var div = document.createElement('div');
div.innerHTML = htmlMarkup;
if (typeof div.innerText != 'undefined'){
return div.innerText;
} else if (typeof div.ownerDocument != 'undefined'
&& typeof div.ownerDocument.createRange != 'undefined'){
var range = div.ownerDocument.createRange();
range.selectNodeContents(div);
return range.toString();
} else if (typeof div.textContent != 'undefined'){
return div.textContent;
}
}

If that is an attempt to extract text from HTML markup, surely a regular
expression is far more satisfactory:

return htmlMarkup.replace(/<[^>]+$/g,'');

should work for most cases, but is not infallible. There is a thread on
it here:

<URL:
http://groups.google.com.au/group/co...72d4e740fe6799
>

--
Rob
Nov 13 '06 #3
RobG wrote:
[...]
... surely a regular expression is far more satisfactory:

return htmlMarkup.replace(/<[^>]+$/g,'');
Agghhh, where'd that dang $ come from? Try:

return htmlMarkup.replace(/<[^>]+/g,'');

--
Rob
Nov 13 '06 #4
ja
>
Agghhh, where'd that dang $ come from? Try:

return htmlMarkup.replace(/<[^>]+/g,'');

--
Rob
Thanks for answer, errors "not well-formed" makes no problems.
i'll try to change function entenityToString with regular expression.

wojtek
Nov 13 '06 #5

ja wrote:

Agghhh, where'd that dang $ come from? Try:

return htmlMarkup.replace(/<[^>]+/g,'');

--
Rob

Thanks for answer, errors "not well-formed" makes no problems.
i'll try to change function entenityToString with regular expression.
Some further testing shows the following work fine in Safari and
Firefox:

<script type="text/javascript">

function htmlContent (htmlString) {
var div = document.createElement('div');
div.innerHTML = htmlString;
if (div.textContent){
return div.textContent;
} else if (div.innerText){
return div.innerText;
} else {
return htmlString.replace(/<[^>]+>/g,'');
}
}

function addDiv(){
var div = document.createElement('div');
div.appendChild(document.createTextNode('New div'));
document.body.appendChild(div);
with (div){
style.border = '1px solid red';
id = 'fred';
}
div.onclick = new Function('alert(this.id);');

// Better to use:
div.onclick = showID;
}

function showID(){ alert(this.id);}
</script>

<button onclick="
alert(htmlContent('<p>Here is some <b>text<b></p>'));
">Run htmlContent()</button>
<button onclick="addDiv();">Run addDiv()</button>
I tried adding the onclick within the with block, and while Firefox
didn't like it, Safari was fine.

Your method of adding onclick attributes using new Function() is less
that optimal, calling the Function object as a constructor is only
marginally better than using eval(). There are other ways of achieving
what you are after, it is much better to add a function reference.

I think you are trying to link back to the parent element by its id and
avoid a clousre, but consider instead going up the parent node tree to
find the parent so that instead of (the vastly over complex):

menuObj.onmouseover = new
Function('delayhide["'+parentNode.id+'Temp"] = true;
if(typeof(delayhide["'+parentNode.id+'"]) !=
"undefined"){clearTimeout(delayhide["'+parentNode.id+'"]);};
if(typeof(delayhide["'+menuObj.id+'"]) !=
"undefined"){clearTimeout(delayhide["'+menuObj.id+'"]);}
showPollDownUnderMenu(\''+underMenusPrefix+'\', \''+menuObj.id+'\',
\''+openerObj.id+'\', true);');
You have:

menuObj.onmouseover = showHide;
and then showHide is like:

function showHide(){
var el = this;
var parent = fnToClimbTreeToParent(el);
...
}

fnToClimbTreeToParent(el){
var parent;
while (el.parentNode && (parent = el.parentNode)) {
if (/parent/.test(parent.id)) return parent;
}
return null;
}
Or if you really want to use getElementById, key the parent ID to the
child's like:

parentID: 'level0'
childID : 'level0_child0'
childID : 'level0_child1'
etc.

var parentID = this.id.replace(/_child*/,'')
var parent = document.getElementById(parentID);

or similar scheme. The idea is to simplify your code and start to find
where the problem is.
--
Rob

Nov 13 '06 #6
ja
or similar scheme. The idea is to simplify your code and start to find
where the problem is.
--
Rob
very thanks, i've changed my function entenityToString with yours
htmlContent
also change metod of adding onclick attributes to something like this:
menuHolder.onmouseout= (function(menu){return
function(e){hidePullDown(menu);}})(menuId);

function hidePullDown(menuId){
....
}

and now everything works fine :)

thanks again
wojtek
Nov 13 '06 #7
ja wrote:
or similar scheme. The idea is to simplify your code and start to find
where the problem is.
--
Rob

very thanks, i've changed my function entenityToString with yours
htmlContent
also change metod of adding onclick attributes to something like this:
menuHolder.onmouseout= (function(menu){return
function(e){hidePullDown(menu);}})(menuId);

function hidePullDown(menuId){
...
}

and now everything works fine :)
A parting comment: that style of attaching a handler to a DOM element
definitely exercises IE's memory leak problem. It may only soak up a
small amount each time, but it may eventually become significant so
make sure you clean-up afterwards by removing (or null-ing) the
handlers you've attached this way.

<URL: http://jibbering.com/faq/faq_notes/closures.html#clMem >
--
Rob

Nov 14 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Josh Renaud | last post: by
5 posts views Thread by Josh Renaud | last post: by
34 posts views Thread by Simon Wigzell | last post: by
2 posts views Thread by darren | last post: by
8 posts views Thread by dd | last post: by
1 post views Thread by Bigpond News Server | last post: by
3 posts views Thread by Amir Michail | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.