- PhantomJS Tutorial
- PhantomJS - Home
- PhantomJS - Overview
- PhantomJS - Environment Setup
- PhantomJS - Object
- PhantomJS - Methods
- WebPage Module
- PhantomJS - Properties
- PhantomJS - Methods
- PhantomJS - Events/Callbacks
- PhantomJS - Child Process Module
- File System Module
- PhantomJS - Properties
- PhantomJS - Methods
- System Module
- PhantomJS - Properties
- Web Server Module
- PhantomJS - Properties
- PhantomJS - Methods
- Miscellaneous
- Command Line Interface
- PhantomJS - Screen Capture
- PhantomJS - Page Automation
- PhantomJS - Network Monitoring
- PhantomJS - Testing
- PhantomJS - REPL
- PhantomJS - Examples
- PhantomJS Useful Resources
- PhantomJS - Quick Guide
- PhantomJS - Useful Resources
- PhantomJS - Discussion
PhantomJS - deleteCookie()
The DeleteCookie () method will help to delete a cookie with the name matching with the existing list of cookies present for a given page URL.
Syntax
Its syntax is as follows −
var wpage = require('webpage').create(); wpage.deleteCookie(cookiename);
Example
The following example shows the use of deleteCookie method.
var wpage = require('webpage').create(); phantom.addCookie ({ 'name' : 'cookie1', /* mandatory property */ 'value' : '1234', /* mandatory property */ 'domain' : 'localhost', /* mandatory property */ 'path' : '/', 'httponly' : true, 'secure' : false, 'expires' : (new Date()).getTime() + (5000 * 60 * 60) }); wpage.open('http://localhost/tasks/a.html', function() { console.log("Cookies available are :"); console.log(JSON.stringify(wpage.cookies)); wpage.deleteCookie('cookie1'); console.log("Cookies available now after deleting cookie1"); console.log(JSON.stringify(wpage.cookies)); phantom.exit(); });
The above program generates the following output.
Cookies available are : [{"domain":".localhost","expires":"Sun, 07 May 2017 10:21:04 GMT","expiry":14941 32664,"httponly":true,"name":"cookie1","path":"/","secure":false,"value":"1234" } ,{"domain":"localhost","expires":"Fri, 22 Dec 2017 12:00:00 GMT","expiry":151394 4000,"httponly":false,"name":"username","path":"/tasks/","secure":false,"value" : "Roy"}] Cookies available now after deleting cookie1 [{"domain":"localhost","expires":"Fri, 22 Dec 2017 12:00:00 GMT","expiry":151394 4000,"httponly":false,"name":"username","path":"/tasks/","secure":false,"value" : "Roy"}]
phantomjs_webpage_module_methods.htm
Advertisements