{"id":2783,"date":"2014-02-16T13:09:00","date_gmt":"2014-02-16T13:09:00","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/02\/16\/check-if-html-element-exists-with-imacros-and-javascript-collection-of-common-programming-errors\/"},"modified":"2014-02-16T13:09:00","modified_gmt":"2014-02-16T13:09:00","slug":"check-if-html-element-exists-with-imacros-and-javascript-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2014\/02\/16\/check-if-html-element-exists-with-imacros-and-javascript-collection-of-common-programming-errors\/","title":{"rendered":"Check if html element exists with iMacros and javascript-Collection of common programming errors"},"content":{"rendered":"<p>I want to check if an HTML element exist with iMacros. If it does, I want to go to a URL. If not, I want to go to other URL.<\/p>\n<p>Because iMacros doesn&#8217;t have statements, I used javascript with the iMacros&#8217; EVAL. Here is the line that handles the javascript execution:<\/p>\n<pre><code>SET !VAR3 EVAL(\"var element = window.content.document.getElementById(\\\"some_element\\\");\nif (typeof(element) != 'undefined' &amp;&amp; element != null) { \nvar redirect = 'http:\/\/192.168.178.22\/sc\/report.php'; \n} else { \nvar redirect = 'http:\/\/192.168.178.22\/sc\/index.php?action=connect'; \n} \nredirect;\n\")\n<\/code><\/pre>\n<p>*It&#8217;s all in one line, but I formatted it for here.<\/p>\n<p>Then, I will redirect with<\/p>\n<pre><code>URL GOTO={{!VAR3}}\n<\/code><\/pre>\n<p>The problem is in both of the cases, the !VAR3 is set to &#8216;undefined.&#8217;<\/p>\n<p>I tried almost the same JS code on Firefox only, and it seems to be working.<\/p>\n<p>Windows 8 with the latest Firefox and the latest iMacros version.<\/p>\n<p>Thank you.<\/p>\n<ol>\n<li>\n<pre><code>var macro;\n\nmacro =\"CODE:\";\nmacro +=\"TAG POS=1 TYPE=DIV ATTR=CLASS:some_class CONTENT=EVENT:MOUSEOVER \";\n\nvar ret=null;\n\nret=iimPlay(macro);\n\nif(ret&gt;0)\n{\n\/\/do something\n}\nelse\n{\n\/\/do something else\n}\n<\/code><\/pre>\n<p>This would be the basic model of the script you want. You just have to insert the proper imacros code.<\/p>\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>I want to check if an HTML element exist with iMacros. If it does, I want to go to a URL. If not, I want to go to other URL. Because iMacros doesn&#8217;t have statements, I used javascript with the iMacros&#8217; EVAL. Here is the line that handles the javascript execution: SET !VAR3 EVAL(&#8220;var element [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2783","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2783","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2783"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2783\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2783"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2783"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2783"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}