www.webdeveloper.com
Results 1 to 4 of 4

Thread: Switch Help

  1. #1
    Join Date
    Jun 2012
    Posts
    4

    Switch Help

    I'm making a bookmarklet that has different variables stored in the switch cases that I want to call depending on what webpage the bookmarklet is used on.

    javascript:
    page=window.location;
    switch(page){
    case "http://page1.html": a=1;b=2;c=3;break;
    case "http://page2.html": a=3;b=2;a=1;break:
    default: alert("window.location= "+page+"");
    };a+b-c=d;$('#box1').val(d)

    This isn't my exact code I tested the bookmarklet without the switch in it and it worked perfectly but when I tried to use the switch all i get is the alert that tells me the page url. I set the default to alert to tell me the page url to see if I put the wrong url in for the case but that wasn't the problem.

    Am I just using switch wrong or did I mess up in the coding?

  2. #2
    Join Date
    Mar 2011
    Posts
    1,252
    If the code you posted is exactly what you're using, then the problem is that 'page' is never going to equal "http://page1.html" or "http://page2.html". You need to use the complete URL including the domain name and any directory names.
    Rick Trethewey
    Rainbo Design

  3. #3
    Join Date
    Jun 2012
    Posts
    4
    Quote Originally Posted by rtrethewey View Post
    If the code you posted is exactly what you're using, then the problem is that 'page' is never going to equal "http://page1.html" or "http://page2.html". You need to use the complete URL including the domain name and any directory names.
    That was an example of what my code is like. I know that the exact code had wouldn't work.
    This is my real code but unless you play that game it cant be tested
    javascript:
    village=window.location;
    switch(village){
    case"http://en63.tribalwars.net/game.php?village=33298&screen=place": sp=0;sw=0;ax=0;ar=0;spy=1;lc=5;ma=0;hv=0;cat=0;ram=0;no=0;kn=0;coords="123|321 456|654 789|987";break;
    case"http://en63.tribalwars.net/game.php?village=33299&screen=place": sp=0;sw=0;ax=0;ar=0;spy=1;lc=2;ma=0;hv=0;cat=0;ram=0;no=0;kn=0;coords="123|321 456|654 789|987";break;
    default: alert("window.location= "+village+"");};coords=coords.split("%20");index=0;farmcookie=document.cookie.match("(^|?"+6333298+"=([^;]*)(;|$)");if(farmcookie!=null)index=parseInt(farmcookie[2]);if(index>=coords.length)alert("Last%20Village");if(index>=coords.length)index=0;coords=coords[index];coords=coords.split("|");index=index+1;cookie_date=new%20Date(2015,11,11);document.cookie=6333298+" ="+index+";expires="+cookie_date.toGMTString();$('#inputx').val(coords[0]);$('#inputy').val(coords[1]);$('#unit_input_spear').val(sp);$('#unit_input_sword').val(sw);$('#unit_input_axe').val(ax);$('#uni t_input_archer').val(ar);$('#unit_input_spy').val(spy);$('#unit_input_light').val(lc);$('#unit_input _marcher').val(ma);$('#unit_input_heavy').val(hv);$('#unit_input_ram').val(ram);$('#unit_input_catap ult').val(cat);$('#unit_input_knight').val(kn);$('#unit_input_snob').val(no);$("#target_attack").foc us();end();

    I wrote this to try to figure out what I was doing wrong but I get the same problem as with my other code.
    javascript:
    sites=window.locaton;
    switch(sites){
    case"https://www.google.com/": a="1";break;
    case"http://www.yahoo.com/": a="2";break;
    default: alert("window.location= "+sites+"");
    };alert(a);end;
    Last edited by jhatear; 07-01-2012 at 01:48 AM.

  4. #4
    Join Date
    Jun 2012
    Posts
    4
    i just switched to a if else statement and it works fine now

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14957 seconds
  • Memory Usage 2,858KB
  • Queries Executed 13 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (1)bbcode_quote
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (4)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (4)postbit
  • (4)postbit_onlinestatus
  • (4)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (71):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates